/*
 * @Autor: PK
 * @Date: 2020-12-25 13:23:06
 * @Description: 可以放入重复元素的SortedList，默认新的重复元素在后，以DateTime作为键，用来保存Agency内的顾客等信息
 */
using System;
using System.Collections.Generic;
using System.Linq;

namespace ShkSimulation.core.util{
    
    public interface IDuplicateComparer<T> : IComparer <T>{
        
        int IComparer<T>.Compare(T x, T y) {
            int result = Compare(x , y);
            return result == 0 ? -1 : result;
        }
        
        public new int Compare(T x, T y);
        
    }

     public class DateTimeComparator : IDuplicateComparer <DateTime>{
         
        private static DateTimeComparator instance;
        
        public static DateTimeComparator EarlyFirst{
            get{
                if(instance == null){
                    lock(typeof(DateTimeComparator)){
                        if(instance == null){
                            instance = new DateTimeComparator();
                        }
                    }
                }
                return instance;
            }
        }
        public int Compare(DateTime x, DateTime y){
            if (x <= y){
                return -1;
            }
            else{
                return 1;
            }
        }
    }


    public class DuplicateSortedList<TKey, TValue> : SortedList<TKey, TValue> {

        public DuplicateSortedList(IDuplicateComparer<TKey> comparer) : base(comparer) {
        }
        
        public TValue RemoveFirstAndGetValue() {
            TValue value = default(TValue);
            if (this.Count == 0) {
                return value;
            }
            value = this.First().Value;
            this.RemoveAt(0);
            return value;
        }

    }


}
